//
//  DateBut.m
//  DA_V
//
//  Created by 中亿世联前台 on 15/5/7.
//  Copyright (c) 2015年 zhouhai. All rights reserved.
//

#import "DateBut.h"
#import "InterFace.h"

@implementation DateBut

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (instancetype) initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    if (self) {
        [self nowTime];
        self.layer.borderColor = [UIColor whiteColor].CGColor;
        self.layer.borderWidth = 1;
        [self setTintColor:[UIColor whiteColor]];
        [self setTitle:self.dateNow forState:UIControlStateNormal];
        self.titleLabel.font = [UIFont fontWithName:nil size:13];
    }
    return self;
}

+ (instancetype) dateButWithButton{

    
    
    DateBut *but = [[DateBut alloc]initWithFrame:CGRectZero];
    if (SCREEN_WIDTH == 320) {
        but.frame = CGRectMake(SCREEN_WIDTH-80,29.5, 60,25);
    }else if (SCREEN_WIDTH == 375){
        but.frame = CGRectMake(SCREEN_WIDTH-80,35, 60,25);
    }else{
        but.frame = CGRectMake(SCREEN_WIDTH-80,48.9, 60,25);
    }
    return but;
}
#pragma mark - 获取当前时间
-(void)nowTime{
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    NSDate *now;
    NSDateComponents *comps = [[NSDateComponents alloc] init];
    NSInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSWeekdayCalendarUnit |
    NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
    now=[NSDate date];
    comps = [calendar components:unitFlags fromDate:now];
    NSInteger year = [comps year];
    NSInteger month = [comps month];
    NSInteger day = [comps day];
    NSString *monthStr ;
    NSString *dayStr ;
    if (month < 10 || day < 10) {
        if (month <10) {
            monthStr = [NSString stringWithFormat:@"0%ld",(long)month];
        }else{
            monthStr = [NSString stringWithFormat:@"%ld",(long)month];
        }
        if(day < 10){
            dayStr = [NSString stringWithFormat:@"0%ld",(long)day];
        }else{
            dayStr = [NSString stringWithFormat:@"%ld",(long)day];
        }
    }else{
        monthStr = [NSString stringWithFormat:@"%ld",(long)month];
        dayStr = [NSString stringWithFormat:@"%ld",(long)day];
    }
    
    //dateNow = [NSString stringWithFormat:@"%ld-%@-%@",(long)year,monthStr,dayStr];
    self.dateNow = [NSString stringWithFormat:@"%ld-%@",(long)year,monthStr];
}

@end
